<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel app\models\search\AsrMobileSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '';
$this->params['breadcrumbs'][] = ['label' => '电话号码列表'];
?>
<div class="asr-mobile-index">

    <p>
        <?= Html::a('上传号码列表', ['create'], ['class' => 'btn btn-info fa fa-plus']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            ['attribute' =>'listname',
                'footer' => '
                    <input id="num" class="btn btn-default btn-xs btn-delete" placeholder="每页显示的条数" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,\'\')}else{this.value=this.value.replace(/\D/g,\'\')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,\'\')}else{this.value=this.value.replace(/\D/g,\'\')}">
                ',
            ],
            ['attribute' => 'create_at',
                'value'=>
                    function($model){
                        if(!empty($model->create_at)){
                            return  date('Y-m-d H:i:s',$model->create_at);   //主要通过此种方式实现
                        }else{
                            return "";
                        }
                    },
            ],
            'mobile_num',
            ['attribute' => 'belong',
                'value'=>
                    function($model){
                        if ($model->belong!=null && $model->belong == 1){
                            return  "自有";
                        }else{
                            return  "他有";
                        }
                    },
            ],

            ['class' => 'yii\grid\ActionColumn',//下面是新增加的按按钮
                'header'=>'操作',
                'template' => ' {detail}&nbsp;&nbsp;&nbsp;{update}&nbsp;&nbsp;&nbsp;{delete} ',
                'buttons' => [
                    'detail' => function ( $url,$model,$key) {
                        return  '<a href="../asr-customer/index?mobile_id='.$key.'"  class="btn btn-success fa fa-sticky-note-o">号码列表</a>';
                    },
                    'update' => function ( $url,$model) {
                        return  '<a href="'.$url.'" class="btn btn-info fa fa-edit">修改</a>';
                    },
                    'delete' => function ( $url,$model) {
                        return  '<a href="'.$url.'" title="删除" aria-label="删除" data-pjax="0" data-confirm="您确定要删除此项吗？删除此项会删除相应的电话号码记录。" data-method="post"><span class="btn btn-danger fa fa-remove">删除</span></a>';
                    },
                ],
                'options'=>[
                    'width'=>'20%',
                ],
                'footerOptions' => ['colspan' => 1],  //设置删除按钮垮列显示；
            ]
        ],
        'filterModel' => $searchModel,
        'showFooter' => true,  //设置显示最下面的footer
        'pager'=>[
            'firstPageLabel'=>"第一页",
            'lastPageLabel'=>'最后一页',
        ],
    ]); ?>
</div>
<script type="text/javascript">
    $('#num').blur(function(){//当鼠标失去焦点是触发事件,实现用户自定义分页
        var url = "<?= 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] ?>";
        $.ajax({
            type:'post',
            async:true,
            url:url,
            data:{pageSize:$('#num').val()},
            success:function(data){
                window.location.reload();
            },
            error:function(error){

            }
        });
    });
    $('#asrRes').click(function(){
        $(this).attr('hidden','hidden');
    });
</script>